let request = require('../../../../utils/request.js')

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  lifetimes: {
    attached: function() {
      console.log('在组件实例进入页面节点树时执行')
      
      // 获取商户停车券
      this.getShopParkTicketList() 
      // 获取已配置商户停车券
      this.getShopParkTicketSet() 
    },
    detached: function() {
      console.log('在组件实例被从页面节点树移除时执行')
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
   * 获取商户停车券
   */
    getShopParkTicketList() {
      request.http(
        '/shop/shop-park-ticket/get-by-shop-id', 'GET', {shopId: wx.getStorageSync('shopId')}
      ).then(res => {
        console.log('商户停车券信息：', res)
        let shopParkTicketList = res.data.data
        this.setData({
          shopParkTicketList: shopParkTicketList
        })
      })
    },
      /**
   * 获取已配置商户停车券
   */
  getShopParkTicketSet() {
    request.http(
      '/shop/park-ticket-set/list', 'GET', {shopId: wx.getStorageSync('shopId')}
    ).then(res => {
      console.log('已配置商户停车券信息：', res)
      this.setData({ shopParkTicketSetList: res.data.data })
    })
  },
    /**
     * 查看详情
     */
    showInfo(e) {
      this.triggerEvent('showInfo', e.currentTarget.dataset.content)
      // this.setData({ content: e.currentTarget.dataset.content, infoDialog: true })
    },
    /**
     * 配置停车券
     */
    setPatkTicket(e){
      let parkTicket = e.currentTarget.dataset.parkTicket
      if(parkTicket.unsettledQuantity > 0){
        wx.navigateTo({ url: '/pages/park-ticket/set-patk-ticket/setPatkTicket?ticketId=' + parkTicket.id })
      } else {
        wx.showToast({ title: '暂无可配置停车券', icon: 'none' })
      }
    },
    /**
   * 释放未领取的引流卷
   */
  release(e){
    let id = e.target.dataset.value;
    let _this = this;
    wx.showModal({
      title: '提示',
      content: '将释放我的引流劵，未领取的信息',
      success: function (res) {
        if (res.confirm) {//这里是点击了确定以后
          request.http(
            '/shop/park-ticket-set/release-shop-park_ticket', 'POST', {id: id}
          ).then(res => {
            if(res.data.code == 200){
              console.log(1)
              wx.showToast({
                title: '释放成功',
                duration: 2000,
                success:function(){
                  setTimeout(function () {
                    _this.getShopParkTicketList()
                    _this.getShopParkTicketSet()
                  }, 1000) 
                }
              })
            }
          })
          console.log('用户点击确定')
        } else {//这里是点击了取消以后
          console.log('用户点击取消')
        }
      }
    })
  },
  }
})
